function s() {
    let tr = document.querySelectorAll('#table .tr');
    //总价
    let allCount = document.querySelector("#allCount");
    //先让总价等于0
    let allCountNum = 0;

    for (let i =0;i<tr.length;i++){
        //单价
        //console.log(tr[i].children[2].children[0].innerHTML);
        var price = tr[i].children[2].children[0].innerHTML;
        //数量
        //console.log(tr[i].children[3].children[0].value)
        var num = tr[i].children[3].children[0].value;
        //小计
        //console.log(tr[i].children[4].children[0].innerHTML);
        var count = tr[i].children[4].children[0].innerHTML = (price * num).toFixed(2);
        console.log(count);

        allCountNum += Number(count)
    }
    //赋值总价
    allCount.innerHTML = allCountNum.toFixed(2);

}

s();

//修改数量的功能
//获取table中所有的input数量
let ipt = document.querySelectorAll("#table .num" );

for (let j = 0; j < ipt.length;j++){
    ipt[j].addEventListener('change',s)
}

//删除功能
let del = document.querySelectorAll(".del");
for(let k = 0;k<del.length;k++){
    del[k].addEventListener('click',function () {
        console.log(this.parentNode);
        var tbody = document.querySelector("#table tbody");
        console.log(tbody);
        //根据父级删除子级
        tbody.removeChild(this.parentNode);
        //删除之后执行一遍函数
        s()
    })
}




